package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.model.domain.LearningPlanDTO;
import com.tianji.learning.model.vo.LearningLessonVO;
import com.tianji.learning.model.vo.LearningPlanPageVO;
import com.tianji.learning.model.vo.LessonStatusVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学生课表 前端控制器
 * </p>
 *
 * @author AvA
 * @since 2024-12-06
 */
@Api(tags = "我的课表相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService lessonService;

    @ApiOperation("查询我的课表")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery query) {
        return lessonService.queryMyLessons(query);
    }

    @GetMapping("/now")
    @ApiOperation("查询当前用户正在学习的课程")
    public LearningLessonVO queryMyCurrentLesson(){
        return lessonService.queryMyCurrentLesson();
    }

    @DeleteMapping("/{courseIds}")
    @ApiOperation("删除课表中课程")
    public void removeUserLessons(@PathVariable List<Long> courseIds){

        Long userId = UserContext.getUser();

        lessonService.removeUserLessons(userId, courseIds);
    }

    @GetMapping("/{courseId}/valid")
    @ApiOperation("检查课程是否有效")
    public Long isLessonValid(@PathVariable Long courseId){
        return lessonService.isLessonValid(courseId);
    }

    @GetMapping("/{courseId}")
    @ApiOperation("查询用户课表中指定课程状态")
    public LessonStatusVO getLessonStatusByCourseId(@PathVariable Long courseId){
        return lessonService.getLessonStatusByCourseId(courseId);
    }

    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程的学习人数")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return lessonService.countLearningLessonByCourse(courseId);
    }

    @ApiOperation("创建学习计划")
    @PostMapping("/plans")
    public void createLearningPlans(@RequestBody LearningPlanDTO planDTO){
        lessonService.createLearningPlans(planDTO.getCourseId(), planDTO.getFreq());
    }

    @ApiOperation("查询我的学习计划")
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlans(PageQuery query){
        return lessonService.queryMyPlans(query);
    }
}
